package fac;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that ThirdRobotLaw is moving to its initial start position (left or right wall).
 * 
 * @author Chris Fang
 */
public class TestTRLInitialMovement extends RobotTestBed {

  boolean visitedWall = false;

  /**
   * Initiates the battle with SittingDuck and ThirdRobotLaw as the participants.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,fac.ThirdRobotLaw";
  }

  /**
   * This test runs for 10 round.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * After each turn, check to see if we're at the left or right wall. If so, set the corresponding
   * flag.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    // Get the snapshot of the robot
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];

    // Get robot's current position
    double xPos = robot.getX();
    // The set the width of all robots
    final double robotWidth = 40.0;
    // Checks to see if the robot visited the left or right wall
    if ((xPos < robotWidth) || (xPos > (width - robotWidth))) {
      visitedWall = true;
    }
  }

  /**
   * After the battle, check to see that we've touched either the left or right wall.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check if visited wall", visitedWall);
  }

}
